﻿using System;
using System.Windows.Forms;

namespace Business.Controls
{
    public class CommandReload : CommandBase
    {
        public CommandReload()
        {
            InitializeComponent();
        }
        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // CommandDelete
            // 
            this.Text = "Atualizar";
            Atalho = Keys.F5;
            this.Click += new System.EventHandler(this.CommandDelete_Click);
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.CommandInsert_KeyDown);
            this.ResumeLayout(false);

        }

        private void CommandInsert_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.KeyData == Atalho)
            {
                Refresh();
            }
        }

        private void Refresh()
        {
            BeforeOperation();
            try
            {
                Form.Reload();
            }
            catch (Exception ex)
            {
                ExibeErro("Erro ao atualizar item.\n");
            }
            AfterOperation();
        }

        private void CommandDelete_Click(object sender, System.EventArgs e)
        {
            Refresh();
        }
    }
}
